package com.cy.personer.web;

import com.cy.personer.bean.Card;
import com.cy.personer.bean.Work;
import com.cy.personer.biz.impl.CardBizImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/ManageCard")
public class ManageCardHandler {
    @Resource
    private CardBizImpl cardBizImpl;

    //展现添加卡页面
    @RequestMapping(value="/showAddCard.action")
    public String showAddCard(){
        return "admin/addCard";
    }

    //检测卡片是否已存在
    @RequestMapping(value="/checkCard.action", method=RequestMethod.POST, produces="application/json;charset=utf-8")
    public @ResponseBody String checkCard(HttpServletRequest request, String cardNumber){
        String result = "error";
        Card card = cardBizImpl.checkCard(cardNumber);
        if (card != null){
            result = "success";
        }
        return result;
    }

    //添加卡片
    @RequestMapping(value="/addCard.action", method=RequestMethod.POST, produces="application/json;charset=utf-8")
    public @ResponseBody String addCard(HttpServletRequest request, Card card){
        String result1 = "error";
        card.setStateId(1);
        boolean result = cardBizImpl.addCard(card);
        if (result){
            result1 = "success";
        }
        return result1;
    }
}
